perf: defer scipy imports to reduce import time#259
Merged
Conversation
Move scipy imports from module level to local function scope in convolver, delaunay interpolator, mask utilities, cholesky, and fnnls modules. This avoids loading scipy during `import autoarray`, cutting ~0.3s from the import floor in smoke tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace all module-level `import matplotlib.pyplot as plt` across plot files with `subplots()` and `get_cmap()` wrappers from plot/utils that import matplotlib lazily on first call. This prevents matplotlib from loading during `import autoarray`, deferring ~0.3s of import cost to first plot use. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Defer all scipy imports from module level to local function scope across convolver, delaunay interpolator, mask utilities, cholesky, and fnnls modules. This avoids loading scipy during
import autoarray, reducing the import floor for downstream packages.Part of PyAutoLabs/PyAutoLens#426.
API Changes
None — internal changes only.
Test Plan
pytest test_autoarray/ -x— 722 passed/smoke-testFull API Changes (for automation & release notes)
No public API changes. All modifications are internal import reorganization:
autoarray/operators/convolver.py—import scipymoved intoConvolverState.__init__autoarray/inversion/mesh/interpolator/delaunay.py—scipy.spatialimports moved into functionsautoarray/mask/mask_2d_util.py—scipy.ndimage.binary_dilationmoved into functionautoarray/util/cholesky_funcs.py—scipy.linalgmoved into functionsautoarray/util/fnnls.py—scipy.linalgmoved into functionautoarray/inversion/inversion/inversion_util.py—fnnls_choleskyimport moved into function🤖 Generated with Claude Code